package connect

import (
	"system/models"
)

func AddSCs(scs models.SC) error {
	err := db.Table("sc").Select("sno", "cno", "grade").Create(&scs).Error
	return err
}

func DelSCs(id string,cno string) error {
	err := db.Table("sc").Where("sno = ? and cno = ?", id,cno).Delete(models.SC{}).Error
	return err
}

func UpdateSCs(scs models.SC) error {
	err := db.Table("sc").Where("sno = ? and cno = ?", scs.Sno,scs.Cno).Updates(&scs).Error
	return err
}

func GetAllSCs(scsParam map[string]interface{}) (error, []models.SC, int64) {
	var scsData []models.SC
	page := scsParam["page"].(int)
	pageSize := scsParam["limit"].(int)
	searchName := scsParam["searchName"].(string)
	var total int64
	err := db.Table("sc").Where("sno like ? ", "%"+searchName+"%").Order("sno ASC").Count(&total).Find(&scsData).Offset((page - 1) * pageSize).Limit(pageSize).Error
	return err, scsData, total
}
